package com.panshi.service.impl;

import com.panshi.vo.InstationVO;
import com.panshi.mapper.UserMapper;
import com.panshi.service.UserService;
import com.panshi.vo.PageSizeVO;
import com.panshi.vo.UserVO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    //@Cacheable(value = "personal",key = "#root.methodName+#uid")
    public UserVO findUserQuery(int uid){
        return  userMapper.findUserQuery(uid);
    }

    @Override
    //@CacheEvict(value="personal",allEntries=true)
    public int updateUser(UserVO userVO) {
        return userMapper.updateUser(userVO);
    }

    @Override
   // @Cacheable(value = "personal",key = "#root.methodName")
    public List<UserVO> findUserQueryList(PageSizeVO pageSizeVO){
        pageSizeVO.setStartIndex(pageSizeVO.getStartIndexInfo());
        return userMapper.findUserQueryList(pageSizeVO);
    }

    public int findCount(){
        return userMapper.findCount();
    }

    @Override
    //@Cacheable(value = "personalIns",key = "#root.methodName")
    public List<InstationVO> findInsQuery(PageSizeVO pageSizeVO) {
        pageSizeVO.setStartIndex(pageSizeVO.getStartIndexInfo());
        return userMapper.findInsQuery(pageSizeVO);
    }

    @Override
    public String judge (UserVO userVO) {
        UserVO u = userMapper.findUserQuerys(userVO.getUid());
        if (u.getPassword().equals(userVO.getPwdOld())){
            userMapper.upDatePossword(userVO);
        }
            return "no";
    }
    public UserVO findUserQuerys(int uid){
        return userMapper.findUserQuerys(uid);
    }
    @Override
    //@CacheEvict(value="personal",allEntries=true)
    public void upDatePossword(UserVO userVO) {
        userMapper.upDatePossword(userVO);
    }


}
